package com.zzj.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zzj.bean.ModelBean;
import com.zzj.dao.ModelDao;
import com.zzj.dao.ProductDao;
import com.zzj.utils.Result;
import com.zzj.utils.StatusCode;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ModelServiceImpl implements ModelService {
    @Resource
    private ModelDao modelDao;
    @Resource
    private ProductDao productDao;

    @Override
    public PageInfo<ModelBean> findAll(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<ModelBean> all = modelDao.findAll();
        return new PageInfo<>(all);
    }

    @Override
    public Result updateModel(ModelBean modelBean) {
        modelBean.setMstate("1");
        int i1 = modelDao.updateModel(modelBean);
        int i2 = productDao.updateProductState(modelBean.getPid(), "3",modelBean.getTid());
        if (i1 == 1 && i2 == 1){
            return new Result();
        }
        return new Result(false, StatusCode.ERROR,"操作失败");
    }
}
